package com.aiyige.page.my.message.notifymessage.collectionmessage.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.page.my.message.notifymessage.collectionmessage.model.CollectionMessage;
import com.aiyige.page.my.message.util.MessageUtil;
import com.aiyige.utils.DateFormatUtil;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuyakun on 2017/8/14.
 */

public class CollectionMessageAdapter extends BaseQuickAdapter<CollectionMessage, CollectionMessageAdapter.ViewHolder> {


    public CollectionMessageAdapter() {
        super(R.layout.collection_message_item, new LinkedList<CollectionMessage>());
    }

    @Override
    protected void convert(ViewHolder helper, CollectionMessage data) {
        helper.bindData(data);
    }

    public static class ViewHolder extends BaseViewHolder {
        @BindView(R.id.otherHeadIv)
        ImageView otherHeadIv;
        @BindView(R.id.otherNameTv)
        TextView otherNameTv;
        @BindView(R.id.otherTimeTv)
        TextView otherTimeTv;
        @BindView(R.id.otherFavouriteMessageTv)
        TextView otherFavouriteMessageTv;
        @BindView(R.id.coverIv)
        ImageView coverIv;
        @BindView(R.id.mediaReleaseDateTv)
        TextView mediaReleaseDataTv;
        @BindView(R.id.mediaTitleTv)
        TextView mediaTitleTv;
        @BindView(R.id.playIv)
        ImageView playIv;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            addOnClickListener(R.id.otherHeadIv);
            addOnClickListener(R.id.otherNameTv);
        }

        public void bindData(CollectionMessage data) {
            otherNameTv.setText(data.getOtherName());
            Glide.with(itemView.getContext())
                    .load(data.getOtherAvatar())
                    .apply(RequestOptions.placeholderOf(R.drawable.default_head))
                    .apply(RequestOptions.circleCropTransform())
                    .into(otherHeadIv);
            Glide.with(itemView.getContext())
                    .load(data.getCover())
                    .apply(RequestOptions.placeholderOf(R.drawable.default_image_bg))
                    .into(coverIv);
            otherTimeTv.setText(DateFormatUtil.getStandardDate(data.getOtherTime()));
            mediaTitleTv.setText(data.getMediaTitle());
            mediaReleaseDataTv.setText(DateFormatUtil.formatMS("yyyy-MM-dd", data.getMediaReleaseDate()));
            playIv.setVisibility(data.getTargetType() == MessageUtil.TARGET_TYPE_VIDEO || data.getTargetType() == MessageUtil.TARGET_TYPE_LEARN_VIDEO ? View.VISIBLE : View.INVISIBLE);
        }
    }
}
